

package tpcar.ejb;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.io.PrintWriter;

/**
 * Defines a stateless bean. This beans provides methods
 * for accessing the card in RO mode.<br>
 * By default, an interface is considered as a local interface if there is no
 * @Remote annotation.
 */
@Stateless(mappedName="consultatorbean")
//@Stateless
public class ConsultatorBean implements Consultator {

    /**
     * Entity manager utilise par ce bean.
     */
    @PersistenceContext
    private EntityManager entityManager = null;

  
    /**
     * @return list of all the card.
     */
    @SuppressWarnings("unchecked")
    public List<CarteDeVisite> listerTous() {
        Query cv = entityManager.createNamedQuery("allCV");
        return cv.getResultList();
    }
	
		/**
     * @return list of cards that match a given name. 
     */
    @SuppressWarnings("unchecked")
		public List<CarteDeVisite> rechercherNom (String nom) {	
				Query cv = entityManager.createNamedQuery("findByName").setParameter("nom",nom);	
        return cv.getResultList();
    }
    
  	/**
     * @return list of cards that mtch a given prefix.
     */
  
 /* @SuppressWarnings("unchecked")  
		public List<CarteDeVisite> rechercherPrefix (String prefix) {
				Query cv = entityManager.createNamedQuery("findByPrefix").setParameter("nom",prefix);	
				
        return cv.getResultList();
		}*/

  @SuppressWarnings("unchecked")  
		public List<CarteDeVisite> rechercherPrefix (String prefix) {
				Query cv = entityManager.createNamedQuery("findByName").setParameter("nom",prefix);	
				
        return cv.getResultList();
		}
}
